home *** CD-ROM | disk | FTP | other *** search
/ An Invitation to the Roland World of Music / Roland - An Invitation To The Roland World Of Music.bin / vb / cooltool / sysex / sysex.frm < prev    next >
Text File  |  1995-04-20  |  19KB  |  625 lines

  1. VERSION 2.00
  2. Begin Form FormSysex 
  3.    BackColor       =   &H00C0C0C0&
  4.    BorderStyle     =   1  'Fixed Single
  5.    Caption         =   "MIDI CoolTools - System Exclusive Example"
  6.    Height          =   4005
  7.    Icon            =   SYSEX.FRX:0000
  8.    Left            =   45
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   3315
  12.    ScaleWidth      =   9255
  13.    Top             =   1125
  14.    Width           =   9375
  15.    Begin Frame FrameSysexList 
  16.       BackColor       =   &H00C0C0C0&
  17.       Caption         =   "Sysex Bank List"
  18.       Height          =   1755
  19.       Left            =   30
  20.       TabIndex        =   11
  21.       Top             =   30
  22.       Width           =   4185
  23.       Begin ListBox ListSysex 
  24.          Height          =   1395
  25.          Left            =   120
  26.          MultiSelect     =   2  'Extended
  27.          TabIndex        =   12
  28.          Top             =   270
  29.          Width           =   3825
  30.       End
  31.    End
  32.    Begin MIDIOutput MIDIOutput1 
  33.       DeviceID        =   0
  34.       Left            =   540
  35.       Top             =   3270
  36.       VolumeLeft      =   0
  37.       VolumeRight     =   0
  38.    End
  39.    Begin MIDIInput MIDIInput1 
  40.       DeviceID        =   0
  41.       Left            =   60
  42.       MaxSysexSize    =   32000
  43.       MessageEventEnable=   0   'False
  44.       Top             =   3270
  45.    End
  46.    Begin CommonDialog CMDialog1 
  47.       DialogTitle     =   "System Exclusive Binary Files"
  48.       Filter          =   "(*.syx) Sysex |*.syx|"
  49.       Left            =   1020
  50.       Top             =   3270
  51.    End
  52.    Begin Frame FrameSysexEdit 
  53.       BackColor       =   &H00C0C0C0&
  54.       Caption         =   "Edit MIDI System Exclusive Message"
  55.       Height          =   1365
  56.       Left            =   30
  57.       TabIndex        =   9
  58.       Top             =   1860
  59.       Width           =   9135
  60.       Begin TextBox TextSysex 
  61.          FontBold        =   0   'False
  62.          FontItalic      =   0   'False
  63.          FontName        =   "MS Sans Serif"
  64.          FontSize        =   8.25
  65.          FontStrikethru  =   0   'False
  66.          FontUnderline   =   0   'False
  67.          Height          =   1005
  68.          Left            =   90
  69.          MultiLine       =   -1  'True
  70.          ScrollBars      =   1  'Horizontal
  71.          TabIndex        =   10
  72.          Text            =   "Text Message"
  73.          Top             =   270
  74.          Width           =   8955
  75.       End
  76.    End
  77.    Begin Frame Frame5 
  78.       BackColor       =   &H00C0C0C0&
  79.       Caption         =   "MIDI Filter"
  80.       Height          =   1755
  81.       Left            =   7410
  82.       TabIndex        =   6
  83.       Top             =   30
  84.       Width           =   1755
  85.       Begin CheckBox CheckMIDIFilter1 
  86.          BackColor       =   &H00C0C0C0&
  87.          Caption         =   "Active Sensing"
  88.          FontBold        =   0   'False
  89.          FontItalic      =   0   'False
  90.          FontName        =   "MS Sans Serif"
  91.          FontSize        =   8.25
  92.          FontStrikethru  =   0   'False
  93.          FontUnderline   =   0   'False
  94.          Height          =   225
  95.          Left            =   150
  96.          TabIndex        =   1
  97.          Top             =   1350
  98.          Value           =   1  'Checked
  99.          Width           =   1395
  100.       End
  101.       Begin CheckBox CheckMIDIFilter2 
  102.          BackColor       =   &H00C0C0C0&
  103.          Caption         =   "Undefined F9"
  104.          FontBold        =   0   'False
  105.          FontItalic      =   0   'False
  106.          FontName        =   "MS Sans Serif"
  107.          FontSize        =   8.25
  108.          FontStrikethru  =   0   'False
  109.          FontUnderline   =   0   'False
  110.          Height          =   225
  111.          Left            =   150
  112.          TabIndex        =   8
  113.          Top             =   840
  114.          Value           =   1  'Checked
  115.          Width           =   1335
  116.       End
  117.       Begin CheckBox CheckMIDIFilter3 
  118.          BackColor       =   &H00C0C0C0&
  119.          Caption         =   "MIDI Time Clock"
  120.          FontBold        =   0   'False
  121.          FontItalic      =   0   'False
  122.          FontName        =   "MS Sans Serif"
  123.          FontSize        =   8.25
  124.          FontStrikethru  =   0   'False
  125.          FontUnderline   =   0   'False
  126.          Height          =   225
  127.          Left            =   150
  128.          TabIndex        =   7
  129.          Top             =   330
  130.          Value           =   1  'Checked
  131.          Width           =   1455
  132.       End
  133.    End
  134.    Begin Frame Frame4 
  135.       BackColor       =   &H00C0C0C0&
  136.       Caption         =   "Receive [In] System Exclusive"
  137.       Height          =   705
  138.       Left            =   4290
  139.       TabIndex        =   4
  140.       Top             =   30
  141.       Width           =   3075
  142.       Begin CommandButton CmdReceiveSysex 
  143.          Caption         =   "Receive Sysex Message"
  144.          FontBold        =   0   'False
  145.          FontItalic      =   0   'False
  146.          FontName        =   "MS Sans Serif"
  147.          FontSize        =   8.25
  148.          FontStrikethru  =   0   'False
  149.          FontUnderline   =   0   'False
  150.          Height          =   315
  151.          Left            =   60
  152.          TabIndex        =   5
  153.          Top             =   270
  154.          Width           =   2925
  155.       End
  156.    End
  157.    Begin Frame Frame3 
  158.       BackColor       =   &H00C0C0C0&
  159.       Caption         =   "Send [Out] System Exclusive"
  160.       Height          =   735
  161.       Left            =   4290
  162.       TabIndex        =   2
  163.       Top             =   750
  164.       Width           =   3075
  165.       Begin CommandButton CmdSendSysex 
  166.          Caption         =   "Send Selected Sysex Message"
  167.          FontBold        =   0   'False
  168.          FontItalic      =   0   'False
  169.          FontName        =   "MS Sans Serif"
  170.          FontSize        =   8.25
  171.          FontStrikethru  =   0   'False
  172.          FontUnderline   =   0   'False
  173.          Height          =   315
  174.          Left            =   60
  175.          TabIndex        =   3
  176.          Top             =   300
  177.          Width           =   2925
  178.       End
  179.    End
  180.    Begin Label LblInQueue 
  181.       BackColor       =   &H00000000&
  182.       Caption         =   " MIDI Sysex Status"
  183.       FontBold        =   0   'False
  184.       FontItalic      =   0   'False
  185.       FontName        =   "MS Sans Serif"
  186.       FontSize        =   8.25
  187.       FontStrikethru  =   0   'False
  188.       FontUnderline   =   0   'False
  189.       ForeColor       =   &H0000FF00&
  190.       Height          =   225
  191.       Left            =   4290
  192.       TabIndex        =   0
  193.       Top             =   1530
  194.       Width           =   3075
  195.    End
  196.    Begin Menu mnuFile 
  197.       Caption         =   "&File"
  198.       Begin Menu mnuFileLoadBank 
  199.          Caption         =   "&Load Bank"
  200.          Shortcut        =   ^L
  201.       End
  202.       Begin Menu MnuSaveBankAs 
  203.          Caption         =   "Save Bank &As..."
  204.          Shortcut        =   ^A
  205.       End
  206.       Begin Menu mnuFileSep1 
  207.          Caption         =   "-"
  208.       End
  209.       Begin Menu mnuFileExit 
  210.          Caption         =   "E&xit"
  211.       End
  212.    End
  213.    Begin Menu mnuMidi 
  214.       Caption         =   "&MIDI"
  215.       Begin Menu mnuMidiSetup 
  216.          Caption         =   "&Setup..."
  217.       End
  218.       Begin Menu mnuMidiThru 
  219.          Caption         =   "&Thru"
  220.          Checked         =   -1  'True
  221.       End
  222.    End
  223. End
  224.  
  225. Option Explicit
  226.  
  227. Dim DisplayBufferString(200) As String
  228. Dim UserMessage As String
  229.  
  230. Sub CheckMIDIFilter1_Click ()
  231.     If CheckMIDIFilter1.Value = 0 Then
  232.     MIDIInput1.Filter(FILTER_F9) = False
  233.     Else
  234.     MIDIInput1.Filter(FILTER_F9) = True
  235.     End If
  236. End Sub
  237.  
  238. Sub CheckMIDIFilter2_Click ()
  239.     If CheckMIDIFilter2.Value = 0 Then
  240.     MIDIInput1.Filter(FILTER_ACTIVE_SENSE) = False
  241.     Else
  242.     MIDIInput1.Filter(FILTER_ACTIVE_SENSE) = True
  243.     End If
  244. End Sub
  245.  
  246. Sub CheckMIDIFilter3_Click ()
  247.     If CheckMIDIFilter3.Value = 0 Then
  248.     MIDIInput1.Filter(FILTER_CLOCK) = False
  249.     Else
  250.     MIDIInput1.Filter(FILTER_CLOCK) = True
  251.     End If
  252. End Sub
  253.  
  254. Sub CmdReceiveSysex_Click ()
  255.     MIDIInput1.Action = MIDIIN_START
  256.  
  257.     
  258.     ' MIDI Data is being received
  259.     LblInQueue.Caption = " Waiting for data..."
  260.  
  261. End Sub
  262.  
  263. Sub CmdReceiveSysex_LostFocus ()
  264.     'UserMessage string is used when data is being received.
  265.     'It is used only to show that progress is happening
  266.     UserMessage = " Receiving data..."
  267. End Sub
  268.  
  269. Sub CmdSendSysex_Click ()
  270.     Dim I As Integer
  271.     Dim n As Integer
  272.     Dim SysexMessage As String
  273.     Dim StringPosition As Integer
  274.  
  275.  
  276.     '**NOTE**
  277.     '
  278.     'If all you want to do is send simple sysex messages, you can format
  279.     'them as simple as this example.  (A Sysex message is sent which resets
  280.     'the Roland SoundCanvas SC-88 to General MIDI mode)
  281.     '
  282.     'Midioutput1.message = &HF0
  283.     'Midioutput1.Buffer = Chr$(&HF0) + Chr$(&H7E) + Chr$(&H7F) + Chr$(9) + Chr$(1) + Chr$(&HF7)
  284.     'Midioutput1.Action = MIDIOUT_SEND
  285.     '
  286.     'In this example the first and last bytes (&HF0 and &HF7) signal the
  287.     'beginning and end of a Sysex message.  The middle bytes are the Sysex
  288.     'message contents.
  289.     
  290.  
  291.     ' MIDI Data is being sent
  292.     LblInQueue.Caption = " Sending data..."
  293.     LblInQueue.Refresh
  294.  
  295.     'Look through ListSysex to see if you have selected some sysex
  296.     'messages to send
  297.     For I = 0 To ListSysex.ListCount - 1
  298.     'When we first received the sysex message we reformated
  299.     'it to make it easier to edit.  Now since we're going to send it,
  300.     'we've got to get it back in its original format
  301.     If ListSysex.Selected(I) = True Then
  302.         SysexMessage = ""
  303.         ListSysex.ListIndex = I
  304.         '
  305.         ' Must tell MIDI CoolTools that this is a sysex message
  306.         MIDIOutput1.Message = &HF0
  307.         
  308.         'Start formating complete sysex message
  309.         SysexMessage = Chr$("&H" + Left(DisplayBufferString(I), 2))
  310.         
  311.         'Starting position of InStr search
  312.         n = 3
  313.  
  314.         'We're going into this loop until we've reformated the complete
  315.         'sysex message
  316.         Do While Len(DisplayBufferString(I)) > n
  317.         '
  318.         'Since we've got a bunch of spaces " " that we've got
  319.         'to find in our reformating, we're going to use the
  320.         'InStr function to help us find them.  Look in the VB
  321.         'Help file if you don't understand InStr!
  322.         StringPosition = InStr(n, DisplayBufferString(I), " ")
  323.         '
  324.         'If 0 then we'll not put in the &H
  325.         If Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)) = "0" Then
  326.             SysexMessage = SysexMessage & Chr$(Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)))
  327.         Else
  328.             'If not 0 but just null, then we do nothing
  329.             If Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)) = "" Then
  330.             'null
  331.             Else
  332.             SysexMessage = SysexMessage & Chr$("&H" & Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)))
  333.             End If
  334.         End If
  335.         n = StringPosition + 2
  336.         Loop
  337.  
  338.         'Complete sysex message is all reformated and now ready
  339.         'to be queued
  340.         MIDIOutput1.Buffer = SysexMessage
  341.         MIDIOutput1.Action = MIDIOUT_QUEUE
  342.  
  343.     End If
  344.     Next I
  345.     MIDIOutput1.Action = MIDIOUT_START
  346. End Sub
  347.  
  348. Sub Form_Load ()
  349.     Dim I As Integer
  350.  
  351.     'UserMessage string is used when data is being received.
  352.     'It is used only to show that progress is happening
  353.     UserMessage = " Receiving data..."
  354.  
  355.     ' Center the form on the screen
  356.     'Move (Screen.Width - Width) \ 2, (Screen.Height - Height) \ 2
  357.  
  358.     FormSysex.Show
  359.     MIDISetupForm.Show MODAL
  360. End Sub
  361.  
  362. Sub Form_Unload (Cancel As Integer)
  363.  
  364.     ' Stop the MIDI In
  365.     MIDIInput1.Action = MIDIIN_STOP
  366.     
  367.     ' Close MIDI In
  368.     MIDIInput1.Action = MIDIIN_CLOSE
  369.  
  370.     
  371.     ' Close MIDI Out
  372.     MIDIOutput1.Action = MIDIOUT_CLOSE
  373.  
  374.     End
  375. End Sub
  376.  
  377. Sub ListSysex_Click ()
  378.     'Display the sysex message that is stored in DisplayBufferString
  379.     TextSysex.Text = DisplayBufferString(ListSysex.ListIndex)
  380. End Sub
  381.  
  382. Sub MIDIInput1_Error (ErrorCode As Integer, ErrorMessage As String)
  383.     '
  384.     ' Midi input error, display message
  385.     '
  386.     MsgBox ErrorMessage
  387.  
  388. End Sub
  389.  
  390. Sub MIDIInput1_Message ()
  391.     Dim n As Integer
  392.     Dim SysexListCount As Integer
  393.  
  394.     SysexListCount = ListSysex.ListCount
  395.  
  396.  
  397.     '
  398.     ' The MIDIInput1.SysexMaxSize property is set to 5000 bytes in this
  399.     ' example.  For larger system exclusive messages, increase this
  400.     ' property. If you are not going to receive system exclusive
  401.     ' message, set the SysexMaxSize property to 0.
  402.     '
  403.  
  404.     '
  405.     'This do while loop allows you to take all the messages that are
  406.     'waiting in the message queue.
  407.  
  408.     Do While MIDIInput1.MessageCount > 0 And Len(MIDIInput1.Buffer) > 0
  409.     'Show the users that data is coming in
  410.     UserMessage = UserMessage + "...."
  411.     LblInQueue.Caption = UserMessage
  412.     LblInQueue.Refresh
  413.     
  414.     '
  415.     'Add each Message to the List box so that the users can click
  416.     'through each message.  We'll set this up to allow the users
  417.     'to view and edit the complete sysex message
  418.     ListSysex.AddItem "Message " & Str(SysexListCount) & " Length=" & Str(Len(MIDIInput1.Buffer))
  419.  
  420.     'A complete sysex message has been received into the
  421.     'MIDIInput.Buffer
  422.     '
  423.     'Now we'll put the first data byte of sysex message into
  424.     'the DisplayBufferString.
  425.     DisplayBufferString(SysexListCount) = Hex(Asc(Left(MIDIInput1.Buffer, 1)))
  426.  
  427.     'Now we're going to go through the remaining portion of the
  428.     'sysex message and get it ready to display.  We'll then be able
  429.     'to view and edit the complete sysex message.
  430.     For n = 2 To Len(MIDIInput1.Buffer)
  431.         DisplayBufferString(SysexListCount) = DisplayBufferString(SysexListCount) & " " & Hex(Asc(Mid(MIDIInput1.Buffer, n, 1)))
  432.     Next n
  433.  
  434.     '
  435.     'DisplayBufferString now contains the sysex message in a viewable
  436.     'format
  437.     '
  438.     'Remove the MIDI data from the MIDI IN queue
  439.     '
  440.     MIDIInput1.Action = MIDIIN_REMOVE
  441.     Loop
  442.  
  443.  
  444.     ' IF the buffer is > 0 then we've received some sysex data
  445.     If Len(DisplayBufferString(SysexListCount)) > 0 Then
  446.     LblInQueue.Caption = " Sysex Data Received!"
  447.     ElseIf mnuMidiThru.Checked = True Then
  448.     'If MIDI Thru is checked in the menu, send non-sysex data out
  449.     MIDIOutput1.Message = MIDIInput1.Message
  450.     MIDIOutput1.Data1 = MIDIInput1.Data1
  451.     MIDIOutput1.Data2 = MIDIInput1.Data2
  452.     MIDIInput1.Action = MIDIIN_REMOVE
  453.     MIDIOutput1.Action = MIDIOUT_START
  454.     MIDIOutput1.Action = MIDIOUT_SEND
  455.     MIDIOutput1.Action = MIDIOUT_STOP
  456.     End If
  457. End Sub
  458.  
  459. Sub MIDIOutput1_Error (ErrorCode As Integer, ErrorMessage As String)
  460.     '
  461.     ' Midi output error, display message
  462.     '
  463.     MsgBox ErrorMessage
  464. End Sub
  465.  
  466. Sub MIDIOutput1_QueueEmpty ()
  467.     '
  468.     'Once queue becomes empty, get ready to record again
  469.     '
  470.     MIDIOutput1.Action = MIDIOUT_STOP
  471.  
  472.     ' MIDI Data is being received
  473.     LblInQueue.Caption = " Data Sent!"
  474.  
  475. End Sub
  476.  
  477. Sub mnuFileExit_Click ()
  478.     ' Stop the MIDI In
  479.     MIDIInput1.Action = MIDIIN_STOP
  480.     
  481.     ' Close MIDI In
  482.     MIDIInput1.Action = MIDIIN_CLOSE
  483.  
  484.     
  485.     ' Close MIDI Out
  486.     MIDIOutput1.Action = MIDIOUT_CLOSE
  487.  
  488.     End
  489. End Sub
  490.  
  491. Sub mnuFileLoadBank_Click ()
  492.     Dim SysexBytes As String
  493.     Dim SysexListCount As Integer
  494.     Dim x As Integer
  495.  
  496.     SysexListCount = ListSysex.ListCount
  497.  
  498.     On Error Resume Next
  499.     CMDialog1.DialogTitle = "Load System Exclusive File"
  500.     CMDialog1.Flags = &H1000&
  501.     CMDialog1.Action = 1
  502.     If (Err) Then
  503.     Exit Sub
  504.     End If
  505.     Open CMDialog1.Filename For Binary As #1
  506.  
  507.     Do While EOF(1) <> True
  508.     SysexBytes = " "
  509.     Get #1, , SysexBytes
  510.     DisplayBufferString(SysexListCount) = LTrim(DisplayBufferString(SysexListCount)) & " " & Hex(Asc(SysexBytes))
  511.     Loop
  512.     
  513.     Close #1
  514.  
  515.     DisplayBufferString(SysexListCount) = Left(DisplayBufferString(SysexListCount), (Len(DisplayBufferString(SysexListCount)) - 2))
  516.     
  517.     ListSysex.AddItem CMDialog1.Filename & " Len =" & Str(Len(DisplayBufferString(SysexListCount)))
  518.     
  519.     'unselect all
  520.     For x = 0 To ListSysex.ListCount - 1
  521.     ListSysex.Selected(x) = False
  522.     Next
  523.  
  524.     'Highlight the loaded file
  525.     ListSysex.Selected(ListSysex.ListCount - 1) = True
  526.  
  527. End Sub
  528.  
  529. Sub mnuMidiSetup_Click ()
  530.     MIDISetupForm.Show MODAL
  531. End Sub
  532.  
  533. Sub mnuMidiThru_Click ()
  534.     'Switch check mark on and off
  535.     If mnuMidiThru.Checked = True Then
  536.     mnuMidiThru.Checked = False
  537.     Else
  538.     mnuMidiThru.Checked = True
  539.     End If
  540. End Sub
  541.  
  542. Sub MnuSaveBankAs_Click ()
  543.     Dim I As Integer
  544.     Dim n As Integer
  545.     Dim SysexMessage As String
  546.     Dim StringPosition As Integer
  547.  
  548.     ' MIDI Data is being sent
  549.     LblInQueue.Caption = " Saving data..."
  550.     LblInQueue.Refresh
  551.  
  552.     On Error Resume Next
  553.     CMDialog1.DialogTitle = "Save Selected Sysex Message"
  554.     CMDialog1.Flags = &H1000&
  555.     CMDialog1.Action = 2
  556.     If (Err) Then
  557.     Exit Sub
  558.     End If
  559.     
  560.     Open CMDialog1.Filename For Binary As #1
  561.  
  562.  
  563.     SysexMessage = ""
  564.  
  565.     'Look through ListSysex to see if you have selected some sysex
  566.     'messages to send
  567.     For I = 0 To ListSysex.ListCount - 1
  568.     'When we first received the sysex message we reformated
  569.     'it to make it easier to edit.  Now since we're going to send it,
  570.     'we've got to get it back in its original format
  571.     If ListSysex.Selected(I) = True Then
  572.         
  573.         ListSysex.ListIndex = I
  574.         '
  575.         
  576.         'Start formating complete sysex message
  577.         SysexMessage = Chr$("&H" + Left(DisplayBufferString(I), 2))
  578.  
  579.         'Write begining F0 sysex byte to file
  580.         Put #1, , SysexMessage
  581.  
  582.         
  583.         'Starting position of InStr search
  584.         n = 3
  585.  
  586.         'We're going into this loop until we've reformated the complete
  587.         'sysex message
  588.         Do While Len(DisplayBufferString(I)) > n
  589.         '
  590.         'Since we've got a bunch of spaces " " that we've got
  591.         'to find in our reformating, we're going to use the
  592.         'InStr function to help us find them.  Look in the VB
  593.         'Help file if you don't understand InStr!
  594.         StringPosition = InStr(n, DisplayBufferString(I), " ")
  595.         '
  596.         'If 0 then we'll not put in the &H
  597.         If Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)) = "0" Then
  598.             SysexMessage = Chr$(Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)))
  599.         Else
  600.             'If not 0 but just null, then we do nothing
  601.             If Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)) = "" Then
  602.             'null
  603.             Else
  604.             SysexMessage = Chr$("&H" & Trim(Mid(DisplayBufferString(I), StringPosition + 1, 2)))
  605.             End If
  606.         End If
  607.  
  608.         'Write sysex data to file
  609.         Put #1, , SysexMessage
  610.  
  611.         n = StringPosition + 2
  612.         Loop
  613.     End If
  614.     Next I
  615.  
  616.     Close #1
  617. End Sub
  618.  
  619. Sub TextSysex_Change ()
  620.     'You can edit the sysex message.  If you do make changes
  621.     'we'll update DisplayBufferString with those changes
  622.     DisplayBufferString(ListSysex.ListIndex) = TextSysex.Text
  623. End Sub
  624.  
  625.